package com.lxyk.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.lxyk.mapper.HistoryMapper;
import com.lxyk.pojo.History;
import com.lxyk.service.HistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

@Service
@Slf4j
public class HistoryServiceImpl extends ServiceImpl<HistoryMapper,History> implements HistoryService {
    @Autowired
    private HistoryMapper historyMapper;

    @Override
    public PageInfo<History> listHistory(Map<String, Object> map, Integer pageNum, Integer pageSize) {
        List<History> historyList = historyMapper.listHistory(map);
        return new PageInfo<>(historyList);
    }

    @Override
    public History getHistoryById(Integer hid) {
        return historyMapper.getHistoryById(hid);
    }

    @Override
    public int updateHistory(History history) {
        return historyMapper.updateHistory(history);
    }

    @Override
    public int batchDeleteHistory(String idList) {
        //字符串转化成List集合
        String[] split = StrUtil.split(idList, ",");
        List<Integer> ids = new ArrayList<>();
        for (String id : split) {
            if (StrUtil.isNotEmpty(id)){
                ids.add(Integer.parseInt(id));
            }
        }
        return historyMapper.batchDeleteHistory(ids);
    }
}
